package com.lb.shopguide.adapter;

import android.graphics.Paint;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.lb.shopguide.R;
import com.lb.shopguide.constants.AppConstant;
import com.lb.shopguide.entity.goods.GoodsInListBean;
import com.lb.shopguide.util.pic.ImageLoaderUtils;
import com.yqritc.recyclerviewflexibledivider.FlexibleDividerDecoration;
import com.yqritc.recyclerviewflexibledivider.HorizontalDividerItemDecoration;

import java.util.List;

/**
 * Created by kang on 2017/6/7.
 */

public class AdapterGoodsList extends BaseQuickAdapter<GoodsInListBean, BaseViewHolder> implements HorizontalDividerItemDecoration.MarginProvider, FlexibleDividerDecoration.PaintProvider {
    public AdapterGoodsList(int layoutResId, List<GoodsInListBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, GoodsInListBean item) {
        View view = helper.itemView;
        TextView tvProductName = view.findViewById(R.id.tv_product_name);
        ImageView ivProductPic = view.findViewById(R.id.iv_product);
        RelativeLayout layoutShader = view.findViewById(R.id.layout_shader);
        TextView tvPrice = view.findViewById(R.id.tv_price);
        TextView tvDistributeMode = view.findViewById(R.id.tv_distribute_mode);

//        ImageLoaderUtils.displayRound(mContext, ivProductPic, item.getProductPicUrl(), 4);

        ImageLoaderUtils.getGlideManager().asBitmap().load(item.getProductPicUrl()).apply(ImageLoaderUtils.getSGCommonGlideOption(4)).into(ivProductPic);
        tvProductName.setText(item.getProductName());
        tvPrice.setText("￥" + item.getPrice());
//        layoutShader.setVisibility(View.VISIBLE);
        if (item.isChecked()) {
            layoutShader.setVisibility(View.VISIBLE);
        } else {
            layoutShader.setVisibility(View.GONE);
        }
        if (item.getDistributeMode() == AppConstant.DISTRIBUTE_MODE_PICK) {
            tvDistributeMode.setVisibility(View.VISIBLE);
            tvDistributeMode.setText("自提");
        } else if (item.getDistributeMode() == AppConstant.DISTRIBUTE_MODE_EXPRESS) {
            tvDistributeMode.setVisibility(View.VISIBLE);
            tvDistributeMode.setText("快递");
        } else {
            tvDistributeMode.setVisibility(View.GONE);
        }
    }

    @Override
    public int dividerLeftMargin(int position, RecyclerView parent) {
        return 190;
    }

    @Override
    public int dividerRightMargin(int position, RecyclerView parent) {
        return 0;
    }

    @Override
    public Paint dividerPaint(int position, RecyclerView parent) {
        Paint paint = new Paint();
        paint.setColor(mContext.getResources().getColor(R.color.sg_common_line_bg_dark));
        paint.setStrokeWidth(2);
        return paint;
    }
}
